<?php

/**
 * This is the model class for table "m_student_monthly_fee".
 *
 * The followings are the available columns in table 'm_student_monthly_fee':
 * @property string $id
 * @property string $student_class_id
 * @property string $ttl_monthly_fee
 * @property string $ttl_disc_fee
 * @property string $ttl_late_fee
 * @property string $start_period
 * @property string $end_period
 * @property integer $student_invoice_id
 *
 * The followings are the available model relations:
 * @property MStudentClass $studentClass
 * @property MStudentHinvoice $studentInvoice
 */
class MStudentMonthlyFee extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student_monthly_fee';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('student_class_id, ttl_monthly_fee, ttl_disc_fee, start_period, end_period, student_invoice_id', 'required'),
			array('student_invoice_id', 'numerical', 'integerOnly'=>true),
			array('student_class_id', 'length', 'max'=>20),
			array('ttl_monthly_fee, ttl_disc_fee, ttl_late_fee', 'length', 'max'=>14),
			array('start_period, end_period', 'length', 'max'=>7),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, student_class_id, ttl_monthly_fee, ttl_disc_fee, ttl_late_fee, start_period, end_period, student_invoice_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'studentClass' => array(self::BELONGS_TO, 'MStudentClass', 'student_class_id'),
			'studentInvoice' => array(self::BELONGS_TO, 'MStudentHinvoice', 'student_invoice_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'student_class_id' => 'Student Class',
			'ttl_monthly_fee' => 'Ttl Monthly Fee',
			'ttl_disc_fee' => 'Ttl Disc Fee',
			'ttl_late_fee' => 'Ttl Late Fee',
			'start_period' => 'Start Period',
			'end_period' => 'End Period',
			'student_invoice_id' => 'Student Invoice',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('student_class_id',$this->student_class_id,true);
		$criteria->compare('ttl_monthly_fee',$this->ttl_monthly_fee,true);
		$criteria->compare('ttl_disc_fee',$this->ttl_disc_fee,true);
		$criteria->compare('ttl_late_fee',$this->ttl_late_fee,true);
		$criteria->compare('start_period',$this->start_period,true);
		$criteria->compare('end_period',$this->end_period,true);
		$criteria->compare('student_invoice_id',$this->student_invoice_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudentMonthlyFee the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
